import type { GraphicObject } from './GraphicObject';

// 核心类型定义
export interface Point {
  x: number;
  y: number;
}

export interface BoundingBox {
  x: number;
  y: number;
  width: number;
  height: number;
}

export interface Transform {
  position: Point;
  rotation: number; // 弧度
  scale: Point;
  anchor: Point; // 变换锚点 (0-1)
}

export interface GraphicStyle {
  fillColor?: string;
  strokeColor?: string;
  strokeWidth?: number;
  opacity?: number;
  lineDash?: number[];
}

export interface ViewTransform {
  offset: Point;
  scale: number;
  rotation: number;
}

export enum GraphicType {
  RECTANGLE = 'rectangle',
  CIRCLE = 'circle',
  POLYGON = 'polygon',
  LINE = 'line',
  TEXT = 'text',
}

export type InteractionMode =
  | 'select'
  | 'move'
  | 'rotate'
  | 'scale'
  | 'create'
  | 'pan'
  | 'zoom';

export enum TransformHandleType {
  MOVE = 'move',
  ROTATE = 'rotate',
  SCALE_X = 'scale_x',
  SCALE_Y = 'scale_y',
  SCALE_XY = 'scale_xy',
}

// 序列化数据类型
export interface GraphicObjectData {
  id: string;
  type: GraphicType;
  transform: Transform;
  style: GraphicStyle;
  layerId: string;
  [key: string]: any; // 具体图形数据
}

export interface LayerData {
  id: string;
  name: string;
  visible: boolean;
  locked: boolean;
  objectIds: string[];
}

export interface WorldData {
  version: string;
  objects: GraphicObjectData[];
  layers: LayerData[];
  viewTransform: ViewTransform;
  history?: any;
}

export interface WorldOptions {
  gridSize?: number;
  gridVisible?: boolean;
  snapToGrid?: boolean;
  backgroundColor?: string;
}

// 事件类型
export interface WorldEventMap {
  initialized: Record<string, unknown>;
  destroyed: Record<string, unknown>;
  objectAdded: { object: GraphicObject };
  objectRemoved: { object: GraphicObject };
  selectionChanged: { selected: GraphicObject[] };
  transformChanged: { object: GraphicObject };
  viewChanged: { transform: ViewTransform };
}

export type WorldEvent = keyof WorldEventMap;
